﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufExtension.h"
#include "IApplicationWindow.h"
#include "IPlatformUiRefreshedEvent.h"

namespace gcmp
{
    class IUiDocument;
    class IModelView;
}

namespace {
    class GnufMainWindowImpl;
}

namespace gnuf {
    class WorkBench;
    class GnufDisplayManager;
    class GnufButtonDefinition;
    class Scenario;

    class GNUF_EXTENSION_EXPORT GnufMainWindow 
        : public gcmp::IApplicationWindow
    {
        DEFINE_CAST_BASE(GnufMainWindow)
    public:
        GnufMainWindow(const wchar_t * configurationsDirectory);
        virtual ~GnufMainWindow();

        static GnufMainWindow * get();
        static gnuf::WorkBench * workBench();
        static gnuf::GnufDisplayManager * displayManager();
        static bool inHourseMode();
        static bool bnufEnabled();

        /// \brief 进入编辑模式
        /// \param hint MainToolbar上的提示信息
        /// \param workspace 指定进入编辑模式后默认的workspace
        /// \param cmdCommitId 编辑模式提交按钮绑定的command，如果不需要请指定空字符串
        /// \param cmdCancelId 编辑模式取消按钮绑定的command，如果不需要请指定空字符串
        /// \return 返回编辑模式的scenario指针
        static Scenario * enterEditMode(
            const std::wstring & hint,
            const std::wstring & workspace,
            const std::wstring & cmdCommitId,
            const std::wstring & cmdCancelId);

        /// \brief 离开当前的编辑模式
        /// \return 
        static bool leaveEditMode();

        /// \brief 刷新Scenario
        /// \return 
        static bool refreshScenario();
        
        // Enter an embedded mode before your logic, otherwise the corresponding
        // logics (e.g. disable some tabs on the ViewTabBar) are out of order.
        // Use the onPostEntered callback, to ignore the above timing sequence.
        static Scenario * enterEmbeddedMode(
            const std::wstring & hint,
            const std::wstring & workspace,
            const std::wstring & cmdCommitId,
            const std::wstring & cmdCancelId,
            const std::function<void()> & onPostEntered = nullptr);
        // Leave the embedded mode after your logic, otherwise the corresponding
        // logics (e.g. disable some tabs on the ViewTabBar) are out of order.
        // Use the onPreLeft callback, to ignore the above timing sequence.
        static bool leaveEmbeddedMode(const std::function<void()> & onPreLeft = nullptr);
        
        virtual std::wstring GetDocumentName(const gcmp::IUiDocument * pUiDoc);
        virtual std::wstring GetViewTypeDisplayName(const gcmp::IModelView* pModelView);

    protected:
        // Inherits from gcmp::IApplicationWindow...
        virtual void ShowMaximized() override;
        virtual void ShowMinimized() override;
        virtual UInt64 GetApplicationWindowId() const override;
        virtual void ActivateWindow() override;
        virtual void ShowApplyOrCancelGui(
            const std::wstring & hint, 
            const std::wstring & applyCmdId, 
            const std::wstring & cancelCmdId) override;
        virtual void HideApplyOrCancelGui() override;
        virtual bool Initialize() override;
        virtual gcmp::IPlatformUiRefreshedEvent * GetPlatformUiRefreshedEvent() const override;
        virtual void Show() override;
        virtual void Hide() override;

    private:
        gcmp::OwnerPtr< GnufMainWindowImpl > m_impl;
    };
}
